<?php
	class Kategori_arsip_model extends Model{
		function Kategori_arsip_model(){
			parent::Model();
		}
        
        function getData($field, $tabel, $where='',$group_by='') {
            $this->db->select($field);
            if ($where!='') {
                $this->db->where($where);
            }
            if ($group_by!='') {
                $this->db->group_by($group_by);
            }
            $query = $this->db->get($tabel);
            if ($query->num_rows() > 0) {
                if ($row = $query->row_array()) {
                    return $row[$field];
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        
        
        
        function kategori_arsip($where="", $num=0, $offset=0, $ro=false) {
            
            if ($where!='') {
                $this->db->where($where);
            }
            
            if ($num > 0) {
                $this->db->limit($num, $offset);
            }
            
	        $this->db->where(array('idpta_kategori_arsip !=' => DISPOSISI));
	        $this->db->where(array('idpta_kategori_arsip !=' => SURAT_KELUAR));
//            $this->db->where('idpta_kategori_arsip NOT LIKE 1'); 
            $query = $this->db->get('kategori_arsip');
            $s = "
              <table align=\"center\" cellspacing=\"1\" cellpadding=\"2\" class=\"tbl\">
                <tbody>
                  <tr>
                    <th class='number'>No</th>
                    <th>Nama</th>
                    <th>Induk</th>
			        <th>Deskripsi</th>                    

                    ";
            if ($ro==false) {
                $s .= " 
                        <th colspan='2'> Aksi </th>";
            }

            $s .= "</tr>
            ";
            if ($num > 0) {
                $i = ($num * ($offset/$num)) + 1;
            } else {
                $i = 1;
            }

            
            
            foreach ($query->result() as $row) {
                
                
                if ($i % 2 == 1 ) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
               
                    
                $induk = $this->getData('nama', 'kategori_arsip', 'idpta_kategori_arsip = '.$row->parent_id.'');
                              
                $s .= "
              <tr class=\"$kelas\">
                
                <td><div align=\"right\">$i.</div></td>                
                <td><div>".$row->nama."</div></td>
                <td><div>$induk</div></td>
                <td><div align=\"center\">".$row->deskripsi."</div></td>
                
                ";
                if ($ro==false) {
                    $s .= "
                    
                    <td><div align='center'> <a href='".base_url()."index_arsip.php/kategori_arsip/edit_kategori_arsip/".$row->idpta_kategori_arsip."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."templates/images/edit.gif' border='0'></a></div></td>   
                    <td><div align='center'> <a href=\"javascript:deleteRow('".$row->idpta_kategori_arsip."')\"><img src='".base_url()."templates/images/del.gif' border='0'></a></div></td>";
                    
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</table>";
            return $s;
        }

        
        function form_kategori_arsip($url,$nama='',$induk='',$deskripsi='',$id='') {
            
                                             

            $ret = "<fieldset>
            <form id='tambahuser' method='post' action='$url'>
              <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">      
                  
                  <tr>
                    <td class=\"kolom\" valign=\"top\">Kategori Induk </td>
                    <td>:</td>
                    <td>".combo_tambah_kategori_arsip('parent_id',$induk,'')."</td>
                  </tr>
                  <tr>
                    <td class=\"kolom\" valign=\"top\">Nama Kategori </td>
                    <td>:</td>
                    <td><input name='nama' id='nama' type='text' size='25' value='$nama'/>
                    <input name='id' id='id' type='hidden' size='15' value='$id'  /></td>
                  </tr>
                  <tr>
                    <td class=\"kolom\" valign=\"top\">Deskripsi </td>
                    <td>:</td>
                    <td><input name='deskripsi' id='deskripsi' type='text' size='100' value='$deskripsi'/></td>
                  </tr>
                
               </table>
               <p>
                  <div >
                          <input class=\"button\" type=\"button\" value=\"<< Kembali\" name=\"btn_kembali\" id=\"btn_kembali\" />&nbsp;
                          <input class=\"button\" type=\"submit\" value=\"Simpan\" name=\"simpan\" />
                  </div>
               </p>
                </form></fieldset>";
                return $ret;
        }
        
        function simpan_kategori_arsip($nama,$induk,$deskripsi,$is_update=FALSE,$id=0) {
            $arr['nama'] = $nama;            
            $arr['parent_id'] = $induk;
            $arr['deskripsi'] = $deskripsi;
              
           
            if ($is_update==FALSE) {
                $this->db->insert('kategori_arsip', $arr);
            } else {
                $this->db->where("idpta_kategori_arsip", $id);
                $this->db->update('kategori_arsip', $arr);
            }
        }
        
        
        
        
	}
?>